package com.springboot.hotel.interceptor;

import com.anji.captcha.util.AESUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//获取session中的用户
        Object sysUser = request.getSession().getAttribute("sysUser");
        if (sysUser == null) {
//            未登录，重定向到登录页面
            response.sendRedirect("/");
            return false;
        } else {
//            已登录，放行
            return true;
        }
    }
}
